package com.friehome.app;

import java.util.List;

import model.LTServiceModel;
import model.PeopleModel;

import org.json.JSONObject;
import org.xutils.x;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import com.dialog.PFDialog;
import com.fragment.Fragment1;
import com.fragment.Fragment2;
import com.fragment.Fragment3;
import com.fragment.Fragment4;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.net.HttpRequestUtil;
import com.net.HttpResponse;
import com.net.TTHttpRequestControll;

import adapter.MainAdapter;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class Main2Activity extends FragmentActivity{

	RelativeLayout oldview;
	
	@ViewInject(R.id.content_main)
	RelativeLayout content_main;
	
	FragmentManager fm;
	
	String id;
	public String dc = "";
	public String deadId = "";
	public String taskId;
	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		setContentView(R.layout.activity_main2);
		x.view().inject(this);
		
		fm = getSupportFragmentManager();
		oldview = content_main;
		
		id = getIntent().getExtras().getString("id");
		
		FragmentTransaction ft = fm.beginTransaction();
		Fragment1 fg1 = new Fragment1();
		Bundle b = new Bundle();
		b.putString("id", id);
		fg1.setArguments(b);
		ft.replace(R.id.realtabcontent, fg1);
		ft.commit();
	}
	@Event(value={R.id.content_main,R.id.content_main2,R.id.content_main3,R.id.content_main4,R.id.content_main5})
	private void onClick(View v){
		if (v.getId() != oldview.getId()) {
			RelativeLayout content = (RelativeLayout)v;
			TextView text = (TextView) content.getChildAt(0);
			text.setTextColor(getResources().getColor(R.color.app_text_main_pressed));
			content.getChildAt(1).setBackgroundColor(getResources().getColor(R.color.app_text_main_pressed));
			
			TextView text2 = (TextView) oldview.getChildAt(0);
			text2.setTextColor(getResources().getColor(R.color.white));
			oldview.getChildAt(1).setBackgroundColor(getResources().getColor(R.color.trans));
			
			oldview = content;
			
			FragmentTransaction ft = fm.beginTransaction();
			Bundle b = new Bundle();
			switch (v.getId()) {
			case R.id.content_main:
				
				Fragment1 fg1 = new Fragment1();
				
				b.putString("id", id);
				fg1.setArguments(b);
				ft.replace(R.id.realtabcontent, fg1);
				
				break;
			case R.id.content_main2:
				if (TextUtils.isEmpty(dc)) {
					Toast.makeText(getApplicationContext(), "无悼词数据", 1).show();
					return;
				}
				Fragment2 fg2 = new Fragment2();
				
				b.putString("id", id);
				b.putString("dc", dc);
				fg2.setArguments(b);
				ft.replace(R.id.realtabcontent, fg2);
				break;
			case R.id.content_main3:
				if (TextUtils.isEmpty(taskId)) {
					Toast.makeText(getApplicationContext(), "无逝者数据", 1).show();
					return;
				}
				PFDialog dialog = new PFDialog(this, new PFDialog.DialogClickListener() {
					
					@Override
					public void onBack(String pf) {
						// TODO Auto-generated method stub
						TTHttpRequestControll.httpPF(getApplicationContext(),taskId ,pf,new HttpRequestUtil.HttpRonspontCallBack() {
							
							@Override
							public void callBack(HttpResponse result) {
								
								try {
									if (result.content.equals("1")) {
										Toast.makeText(getApplicationContext(), "提交成功", Toast.LENGTH_LONG).show();

									}else{
										Toast.makeText(getApplicationContext(), "提交失败", Toast.LENGTH_LONG).show();
									}
								} catch (Exception e) {
									e.printStackTrace();
								}
								
									
								
							}
						});
					}
				});
				dialog.showDialog();
				
				break;
			case R.id.content_main4:
				Fragment3 fg3 = new Fragment3();
				
				b.putString("id", id);
				fg3.setArguments(b);
				ft.replace(R.id.realtabcontent, fg3);
				break;
			case R.id.content_main5:
				
				if (TextUtils.isEmpty(deadId)) {
					Toast.makeText(getApplicationContext(), "无逝者数据", 1).show();
					return;
				}
				Fragment4 fg4 = new Fragment4();
				
				b.putString("id", deadId);
				fg4.setArguments(b);
				ft.replace(R.id.realtabcontent, fg4);
				
				break;
			default:
				break;
			}
			ft.commit();
			
		}
	}
	
	@Event(value={R.id.btn_back})
	private void finishClick(View v){
		finish();
	}
}
